package conteoller;

import biz.SizeBiz;
import com.google.gson.Gson;
import entity.SizetbEntity;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

/*
 * @Description：
 *       尺寸数据处理
 * @Author: JiangFan
 * @Date: 2019/3/9
 * @Time：9:35
 */
@WebServlet("/size")
public class SizeServlet extends BaseServlet {
    SizeBiz sb=new SizeBiz ();
    SizetbEntity se=new SizetbEntity ();

    /**
     * 查询所有尺寸信息
     * @param req
     * @param reps
     * @return 返货json值
     */
    public String querySizeAll (HttpServletRequest req, HttpServletResponse reps)
            throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException {
        List<SizetbEntity> list=sb.querySizeAll ();
        Gson gson=new Gson ();
        String json=gson.toJson (list);
        return json;
    }
    public String querySizeOne(HttpServletRequest req,HttpServletResponse resp) throws IOException {
        //取编号
        String size=req.getParameter ("txtSize");
        //调用Biz查询方法,查询颜色是否可用
        try {
            boolean ce=sb.checkSize (size);
            if (ce){
                resp.getWriter ().write ("尺寸可用");
            }else {
                resp.getWriter ().write ("尺寸已存在");
            }
        }catch (Exception e){
            //响应错误消息文本
            resp.getWriter ().write ("尺寸不可用");
        }
        return null;
    }
}
